<script> function start_game() { var size = document.getElementById('size').value; document.getElementById('output_message').innerHTML = 'If you expect everything, you will get everything.'; // _TWTG_initialize(size); } </script> ... Size: <input id='size' type='number' min='2' max='5' value='3'></input> <button id='start_button' onclick='start_game()'>Start the game</button> <p id='output_message'></p> ...
data
be an array. Is data[i]
a variable?n
, from the user.
Let's read n values from the user and save them into an array.
Let's compute the average and display it in a <p>
.
var course = ['comp2680', 'comp3540', 'comp4620']; var person = {fname:"John", lname:"Doe", age:25}; var str = "<table>"; str += "<tr>"; for (let p in person) str += '<td>' + person[p] + '</td>'; str += '</tr>'; str += "<tr>"; for (let p in course) str += '<td>' + course[p] + '</td>'; str += '</tr>'; person[0] = 'Tom'; person[1] = 'Williams'; person[2] = '22'; str += "<tr>"; for (let p in person) str += '<td>' + person[p] + '</td>'; str += '</tr>'; str += '</table>'; window.alert(str);
function toCelsius(f) { return 5 / 9 * (f - 32); } temp = toCelsius; document.write(temp(66));
prompt()
and
check if the number is a prime number using the above function.
n
, from the user.n
values from the user, save them into an array and returns the array.
n
is passed to the function as an argument.
var person = { firstName:"John", lastName:"Doe", age:50, eyeColor:"blue", getFullName: function() { return this.firstName + " " + this.lastName; } }; document.write(person.age + '<br>'); document.write(person['age'] + '<br>'); // Objects behave like arrays, and arrays are objects. document.write(person.fullName() + '<br>'); document.write(person['getFullName']() + '<br>'); // Objects behave like arrays, and arrays are objects.
var str = ' Amazing Spiderman! \n'; alert('**' + str + '**'); str = str.trim(); alert('**' + str + '**');
<!DOCTYPE html> <head> <style> /* CSS rules to style the HTML elements in the body element. */ </style> <script> // Variables // Control statement, such as assignment, if-else, for, for/in, while, do-while, switch, function invokation statements // Functions // Functions (event handlers) // Invoked when events are triggered on HTML elements in the body element // Control HTML elements in the body element </script> </head> <body> <!-- HTML elements --> <!-- Some HTML elements have ids. --> <!-- Some HTML elements have onclick='javascript code'. --> <script> </script> </body> </html> <script> </script>